package DB;
        import java.sql.*;
public class DB {
    private Connection dbConn;
    private Statement stateMent;
    public DB(){
        //JDBC驱动
        String driverName = "com.mysql.cj.jdbc.Driver";
        String url = "jdbc:mysql://localhost:3306/os?useSSL=false" +
                "&useUnicode=true&characterEncoding=UTF8 &useLegacyDatetimeCode=false&serverTimezone=UTC";
        String username = "yuruiqiao";
        String passworld = "15162823853";

        try {
            Class.forName(driverName);
            dbConn=DriverManager.getConnection(url,username,passworld);
//            System.out.println("连接成功");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }

    }
    public int executeUpdate(String sql) throws SQLException{
        stateMent = dbConn.createStatement();
        return stateMent.executeUpdate(sql);
    }
    public ResultSet executeQuery(String sql) throws SQLException{
        stateMent = dbConn.createStatement();
        return stateMent.executeQuery(sql);
    }
    public void closeConn() throws SQLException {
        stateMent.close();
        dbConn.close();
    }
    //添加创建预处理对象的方法
    public PreparedStatement PreparedStatement(String sql) throws SQLException{
        return dbConn.prepareStatement(sql);
    }

}
